package video;

import java.io.File;

import org.gstreamer.Bus.EOS;

import rss.News;

/**
 * Class that receives a News, that provides the RSS feeds, and overlay the
 * video with then.
 * 
 * @version 0.3 December 01, 2009.
 * @author Heitor Meira de Melo.
 */
public class VideoPlayer extends MediaPlayer {
	private String video_news = "bailey.flv";
	private News news;

	/**
	 * Constructor of a VideoPlayer.
	 * 
	 * @param endOfVideo
	 */
	public VideoPlayer(EOS endOfVideo) {
		super(endOfVideo);
	}

	/**
	 * Constructor of a VideoPlayer.
	 * 
	 * @param endOfVideo
	 */
	public VideoPlayer(EOS endOfVideo, News news) throws Exception {
		this(endOfVideo);
		// if(news == null){
		// throw new
		// Exception("Adicione uma URL de um feed antes de iniciar a exibição!");
		// }
		this.news = news;
	}

	/**
	 * Set the News class to manager the notices, the default configuration is
	 * "Sem reposta de noticias"
	 * 
	 * @param news
	 *            News class that manager the news.
	 */
	public void setNews(News news) {
		this.news = news;
	}

	/**
	 * Set the text that overlay the video. When the it is the new's video.
	 * 
	 * @param video
	 *            To know if the current video is the news video.
	 * @throws Exception
	 */
	private void setText(File video) {
		if (video_news.equals(video.getName())) {
			if (news == null) {
				getRunVideo().setText("Sem resposta de noticias");
			} else {
				getRunVideo().setText(news.getANewsTitle());
			}
		} else {
			getRunVideo().setText("");
		}
	}

	/**
	 * Set the (Video News Name). The Video News Name is the name of the video
	 * that will show the new. News are called when this video is current in the
	 * play list.
	 * 
	 * @param newVideoName
	 *            The new Video News Name.
	 */
	public void setVideoNewsName(String newVideoName) {
		video_news = newVideoName;
	}

	@Override
	public void setInputPlaybinFile(File video) {
		super.setInputPlaybinFile(video);
		setText(video);
	}

}
